package ar.com.e2solver.view;
import java.awt.BorderLayout;
import java.awt.Dimension;
import java.awt.Toolkit;

import javax.swing.JFrame;

import ar.com.e2solver.model.Puzzle;


public class SimplePuzzleView {
	
	private Puzzle puzzle;
	private JFrame mainFrame;
	
	public SimplePuzzleView(Puzzle puzzle) {
		this.puzzle = puzzle;
		
	    BorderLayout bl = new BorderLayout();
	    bl.setHgap(10);
		this.mainFrame = new JFrame("E2Solver");
	    this.mainFrame.setLayout(bl);
		this.mainFrame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
		
	    draw();
	    centerFrame();
	}
	
	public void draw(){
		
	    this.mainFrame.add(new PuzzleView(puzzle), BorderLayout.CENTER);
		this.mainFrame.pack();
		this.mainFrame.setVisible(true);
	}
	

	private void centerFrame(){
	    Toolkit toolkit = Toolkit.getDefaultToolkit();
	    Dimension screenSize = toolkit.getScreenSize();

	    int x = (screenSize.width - this.mainFrame.getWidth()) / 2;
	    int y = (screenSize.height - this.mainFrame.getHeight()) / 2;

	    this.mainFrame.setLocation(x, y);		
	}

}
